import java.util.Arrays;

/**
 * 打印数组
 */
public class Demo08 {
    public static void main(String[] args) {
        int[] arr = {1, 5, 54, 145, 12};
        System.out.println(printArr(arr));
    }

    /**
     * 返回数组的字符串
     *
     * @param a int类型的数组
     * @return [1, 2, 2]返回类似这种格式的字符串
     */
    public static String printArr(int[] a) {
        if (a == null)
            return "null";
        int iMax = a.length - 1;
        if (iMax == -1)
            return "[]";

        String b = "[";
        for (int i = 0; ; i++) {
            b += a[i];
            if (i == iMax)
                return b + "]";
            b += ",";
        }
    }
}
